package CCRMClient.GUI;

import javax.swing.JPanel;

import java.awt.CardLayout;
import java.awt.Color;

import javax.swing.border.LineBorder;
import javax.swing.JLabel;

import java.awt.Font;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
import javax.swing.JButton;

import CCRMClient.ClientStart;
import Common.SERVER_COMMANDS;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.IOException;
import org.eclipse.wb.swing.FocusTraversalOnArray;
import java.awt.Component;

/**
 * This class implements the catalog management screen panel
 * @author Ori Ziv
 *
 */
public class CatalogScreen extends JPanel {
	
	private JLabel lblCatalogManagment;
	private JButton btnAddCategory;
	private JButton btnGoBack;
	private JButton btnAddTypes;
	private JButton btnAddProduct;
	private JButton btnUpdateProduct;
	

	/**
	 * Create the panel.
	 */
	public CatalogScreen() {
		
		initialize();
	}
	/**
	 * Initiate the panel
	 */
	private void initialize() {
		setSize(470, 350);
		setBorder(new LineBorder(new Color(0, 0, 0)));
		setBackground(Color.WHITE);
		setLayout(null);
		add(getLblCatalogManagment());
		add(getBtnAddCategory());
		add(getBtnGoBack());
		add(getBtnAddTypes());
		add(getBtnAddProduct());
		add(getBtnUpdateProduct());
		setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{getBtnAddCategory(), getBtnAddTypes(), getBtnAddProduct(), getBtnUpdateProduct(), getBtnGoBack()}));
	}
	/**
	 * @return Catalog Management label for the panel title
	 */
	JLabel getLblCatalogManagment() {
		if (lblCatalogManagment == null) {
			lblCatalogManagment = new JLabel("Catalog Management");
			lblCatalogManagment.setHorizontalAlignment(SwingConstants.CENTER);
			lblCatalogManagment.setForeground(Color.RED);
			lblCatalogManagment.setFont(new Font("David", Font.BOLD, 26));
			lblCatalogManagment.setBackground(Color.WHITE);
			lblCatalogManagment.setBounds(0, 0, 470, 49);
		}
		return lblCatalogManagment;
	}
	/**
	 * @return Add category button
	 */
	JButton getBtnAddCategory() {
		if (btnAddCategory == null) {
			btnAddCategory = new JButton("Add Category");
			btnAddCategory.addActionListener(new BtnAddCategoryActionListener());
			btnAddCategory.setFont(new Font("Tahoma", Font.BOLD, 12));
			btnAddCategory.setBounds(10, 60, 124, 23);
		}
		return btnAddCategory;
	}
	/**
	 * @return Quit button
	 */
	JButton getBtnGoBack() {
		if (btnGoBack == null) {
			btnGoBack = new JButton("Go Back");
			btnGoBack.addActionListener(new BtnQuitActionListener());
			btnGoBack.setFont(new Font("Tahoma", Font.BOLD, 12));
			btnGoBack.setBounds(171, 266, 124, 23);
		}
		return btnGoBack;
	}
	/**
	 * This inner class implements event listener for pressing Go Back button
	 * @author Ori Ziv
	 *
	 */
	private class BtnQuitActionListener implements ActionListener {
		public void actionPerformed(ActionEvent arg0) {
			ClientStart.panelSwicher(new MarketingScreen());
		}
	}
	/**
	 * This inner class implements event listener for pressing Add Category button
	 * @author Ori Ziv
	 *
	 */
	private class BtnAddCategoryActionListener implements ActionListener {
		public void actionPerformed(ActionEvent arg0) {
			if (!ClientStart.user.getPosition().equals("Marketing Manager"))
				JOptionPane.showMessageDialog(null, "You are not authorized to do this action!", "Security Issue", JOptionPane.ERROR_MESSAGE);
			else {
				AddCategoryScreen addCatScrn = new AddCategoryScreen ();
				ClientStart.panelSwicher(addCatScrn);
			}
		}
	}
	/**
	 * This inner class implements event listener for pressing Add Type button
	 * @author Ori Ziv
	 *
	 */
	private class BtnAddTypesActionListener implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			ClientStart.panelSwicher(new AddTypeScreen());
		}
	}
	/**
	 * This inner class implements event listener for pressing Add Product button
	 * @author Ori Ziv
	 *
	 */
	private class BtnAddProductActionListener implements ActionListener {
		public void actionPerformed(ActionEvent arg0) {
			AddProductScreen addPrdScrn = new AddProductScreen();
			ClientStart.panelSwicher(addPrdScrn);
		}
	}
	/**
	 * This inner class implements event listener for pressing Update Product button
	 * @author Ori Ziv
	 *
	 */
	private class BtnUpdateProductActionListener implements ActionListener {
		public void actionPerformed(ActionEvent arg0) {
			ClientStart.panelSwicher(new UpdateProductScreen());
		}
	}
	JButton getBtnAddTypes() {
		if (btnAddTypes == null) {
			btnAddTypes = new JButton("Add Types");
			btnAddTypes.addActionListener(new BtnAddTypesActionListener());
			btnAddTypes.setFont(new Font("Tahoma", Font.BOLD, 12));
			btnAddTypes.setBounds(10, 105, 124, 23);
		}
		return btnAddTypes;
	}
	JButton getBtnAddProduct() {
		if (btnAddProduct == null) {
			btnAddProduct = new JButton("Add Product");
			btnAddProduct.addActionListener(new BtnAddProductActionListener());
			btnAddProduct.setFont(new Font("Tahoma", Font.BOLD, 12));
			btnAddProduct.setBounds(299, 60, 138, 23);
		}
		return btnAddProduct;
	}
	JButton getBtnUpdateProduct() {
		if (btnUpdateProduct == null) {
			btnUpdateProduct = new JButton("Update Product");
			btnUpdateProduct.addActionListener(new BtnUpdateProductActionListener());
			btnUpdateProduct.setFont(new Font("Tahoma", Font.BOLD, 12));
			btnUpdateProduct.setBounds(299, 105, 138, 23);
		}
		return btnUpdateProduct;
	}
}
